import React from "react";
import {inject, observer} from "mobx-react";
import {withRouter} from "react-router-dom";
import {Accordion, Icon, InputItem, List, Select, Tools} from "weaver-mobile";
import {RouteLayout} from "weaver-mobile-page";
import {observable} from "mobx";

const getLabel = Tools.getLabel;

const quoteStatusOption = [
    {key: "0", showname: getLabel(220, "草稿")},
    {key: "1", showname: getLabel(19134, "审批中")},
    {key: "2", showname: getLabel(236, "退回")},
    {key: "3", showname: getLabel(508866, "已通过")},
];
const quoteTypeOption = [
    {key: "1", showname: getLabel(19398, "月度")},
    {key: "2", showname: getLabel(17495, "季度")},
    {key: "3", showname: getLabel(20729, "半年")},
    {key: "4", showname: getLabel(17138, "年度")}
];

/**
 * 引用方案-条件
 * jiansong 2019/11/8
 */
@inject("programViewStore")
@withRouter
@observer
export default class QuoteCondition extends React.Component {

    constructor(props) {
        super(props);
        this.store = this.props.programViewStore;
    }

    render() {
        const {quoteParams, handleQuoteParamsChange} = this.store;
        return (
            <div className="wm-route-layout workrelate-condition">
                <Accordion defaultActiveKey="0">
                    <Accordion.Panel header={getLabel(32905, "常用条件")} className="custom-header">
                        <List>
                            <List.FormItem
                                extra={<Icon type="editor" size="xxs"/>}
                                label={getLabel(33439, "名称")}
                                line
                                noBorder
                                content={<InputItem
                                    placeholder={getLabel(83869, "请输入")}
                                    value={quoteParams.programname}
                                    onChange={val => handleQuoteParamsChange({"programname": val})}
                                />}
                            />
                        </List>
                        <List>
                            <List.FormItem
                                noBorder
                                content={
                                    <Select
                                        value={quoteParams.programtype}
                                        options={quoteTypeOption}
                                        label={getLabel(500401, "类型")}
                                        onChange={val => handleQuoteParamsChange({"programtype": val})}
                                    />}
                            />
                        </List>
                        <List>
                            <List.FormItem
                                noBorder
                                content={
                                    <Select
                                        value={quoteParams.status}
                                        options={quoteStatusOption}
                                        label={getLabel(23247, "状态")}
                                        onChange={val => handleQuoteParamsChange({"status": val})}
                                    />}
                            />
                        </List>
                    </Accordion.Panel>
                </Accordion>
                <RouteLayout.ButtonGroup data={this.buildButtons()}/>
            </div>
        )
    }

    //获取操作按钮
    buildButtons = () => {
        const {programQuoteStore, handleQuoteParamsChange, handleResetQuoteCondition, buildQuoteData} = this.store;
        return [{
            key: "reset", text: getLabel(2022, "重置"),
            onClick: () => handleResetQuoteCondition(),
        }, {
            key: "search", text: getLabel(388113, "搜索"), type: "primary",
            onClick: () => {
                handleQuoteParamsChange({current: 1});
                buildQuoteData(false);
                this.props.history.go(-1)
            },
        }];
    }

}

